package com.bnz.search.listener;

import com.alibaba.fastjson.JSON;
import com.bnz.search.entity.ItemEntity;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
@RabbitListener(queues = "updateStatus")
public class MyRmqGoodsListener {

	@Autowired
	private ElasticsearchRestTemplate restTemplate;

	@RabbitHandler
	public void updateStatus(String itemEntities){
		//1、将得到的sku列表转换为对象
		List<ItemEntity> entities = JSON.parseArray(itemEntities, ItemEntity.class);
		//2、更新到索引库中
		restTemplate.save(entities);
		//3、提示
		System.out.println("更新到索引库成功！");
	}
}
